package strategy;

/**
 * 上下文：支付上下文类
 *
 * @author Liu Yicong
 * @date 2025/9/23
 */
public class PaymentContext {
	private PaymentStrategy paymentStrategy; // 维护一个策略引用

	public void setPaymentStrategy(PaymentStrategy strategy) {
		this.paymentStrategy = strategy;
	}

	public void executePayment(double amount) {
		if (paymentStrategy == null) {
			throw new IllegalStateException("未设置支付策略。");
		}
		// 委托给具体的策略对象
		paymentStrategy.pay(amount);
	}
}
